import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { IView } from "../../mvc/interfaces/IView";
import { RandomPropModule } from "../../../modules/RandomPropModule";
import { DataEvent } from "../events/DataEvent";
import { ItemData } from "../resource/info/ItemData";
import { ItemsUtil } from "../view/shortcuts/item/ItemsUtil";
import { IRandomPropModule } from "../../../modules/interfaces/IRandomPropModule";
import { GameProxy } from "../mvc/GameProxy";
type int = number;
//class RandomPropController
    
    export  class RandomPropController extends Controller
    {
        constructor()
        {
            
            super();Dispatcher.addEventListener(EventName.RandomPropOpen, this.onRandomPropOpenHandler);
            Dispatcher.addEventListener(EventName.RandomPropUseItem, this.onRandomPropUseItemHandler);
            Dispatcher.addEventListener(EventName.RandomPropUseItemSuccess, this.onRandomPropUseItemSuccessHandler);
            return;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            return;
        }

        public /* override */ get view(): IView
        {
            if (!this._randomModule) 
            {
                this._randomModule = new RandomPropModule();
            }
            return this._randomModule;
        }

        /* internal  */onRandomPropOpenHandler(arg1: DataEvent): void
        {
            var loc3=null;
            var loc1=arg1.data["itemData"] as ItemData;
            var loc2=arg1.data["amount"] as int;
            if (ItemsUtil.isRandItemPetSkill(loc1) || ItemsUtil.isRandItemJewel(loc1)) 
            {
                loc3 = cache.randomProp.getRandomListDataProvider(loc1, -1, loc2);
                (this.view as IRandomPropModule).updateListByDataProvider(loc3);
                this.view.show();
            }
            return;
        }

        /* internal  */onRandomPropUseItemHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["randType"] as int;
            var loc2=arg1.data["itemData"] as ItemData;
            var loc3=arg1.data["uidItemDict"] as Map<any, any> /* flash.utils.Dictionary */;
            GameProxy.packProxy.useRandItem(loc1, loc2, loc3);
            return;
        }

        /* internal  */onRandomPropUseItemSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as ItemData;
            if (ItemsUtil.isRandItemPetSkill(loc1) || ItemsUtil.isRandItemJewel(loc1)) 
            {
                if (this._randomModule) 
                {
                    this._randomModule.hide();
                }
            }
            return;
        }

        private /* var */_randomModule: IRandomPropModule;
    }
